package com.yuanzong.wuliu.service.app.system.apk;

import cn.hutool.core.collection.CollUtil;
import com.yuanzong.wuliu.common.exception.BusinessException;
import com.yuanzong.wuliu.common.vo.ApiResult;
import com.yuanzong.wuliu.common.vo.ApiResultPage;
import com.yuanzong.wuliu.controller.intercdeptor.AppHandlerInterceptorAdapter;
import com.yuanzong.wuliu.model.business.customer.BusinessCustomer;
import com.yuanzong.wuliu.model.system.apk.SystemApk;
import com.yuanzong.wuliu.model.system.apk.query.SystemApkPageQuery;
import com.yuanzong.wuliu.service.system.apk.factory.SystemApkFactory;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class AppSystemApkService {

    public ApiResult newVersion() throws Exception {
        // ===================================================================================//
        // ===== 当前登陆用户
        // ===================================================================================//
        BusinessCustomer runtimeUser = AppHandlerInterceptorAdapter.getRuntimeUser();
        // ===================================================================================//
        // ===== 业务执行
        // ===================================================================================//
        SystemApkPageQuery systemApkPageQuery = new SystemApkPageQuery();
        systemApkPageQuery.setPageNum(1);
        systemApkPageQuery.setPageSize(1);
        ApiResultPage<SystemApk> apiResultPage = SystemApkFactory.getSystemApkService().pageSubject(systemApkPageQuery);
        SystemApk systemApk = null;
        if (CollUtil.isNotEmpty(apiResultPage.getRecords())) {
            systemApk = apiResultPage.getRecords().get(0);
        }
        return ApiResult.success(systemApk);
    }
}
